<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资产包信息列表</title>
<style type="text/css">
    .searchArea .fieldBox .label{width: 80px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
</style>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
          <div class="fieldBox" >
                <div class="label">融资基数</div>
                <div class="field">
                <select name="fncCrdnlt" id="fncCrdnlt" data-value=" " ligerui="width: 200">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${fncCrdnltList }" var="fc">
                     		<option value="${fc.key }">${fc.value }</option>
                        </c:forEach>
                </select>
                </div>
            </div> 
			<div class="fieldBox">
                <div class="label">客户类型</div>
                <div class="field">
                    <select name="cstTypCd" id="cstTypCd" data-value=" " ligerui="width: 200">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${cstTypCdList }" var="ct">
                     		<option value="${ct.key }">${ct.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>        
			<div class="fieldBox">
                <div class="label">所属事业部</div>
                <div class="field">
                	<input name="buOrgCd" id="buOrgCd" type="text" class="ui-textbox" data-value=" " placeholder="--请选择--" ltype="combobox" value="" ligerui="width: 200">
                    <%-- <select name="buOrgCd" id="buOrgCd" data-value=" " ligerui="width: 200">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${buOrgCdList }" var="bo">
                     		<option value="${bo.key }">${bo.value }</option>
                        </c:forEach>
                    </select> --%>
                </div>
            </div>        
			<div class="fieldBox">
                <div class="label">是否办理抵押</div>
                <div class="field">
                    <select name="isMortgage" id="isMortgage" data-value=" " ligerui="width: 200">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${isMortgageList }" var="im">
                     		<option value="${im.key }">${im.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>        
			<div class="fieldBox">
                <div class="label">是否有保险</div>
                <div class="field">
                    <select name="isInsurance" id="isInsurance" data-value=" " ligerui="width: 200">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${isMortgageList }" var="im">
                     		<option value="${im.key }">${im.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>        
            <div class="fieldBox">
                <div class="label">租赁期数</div>
                <div class="field">
                   <input name="leaseTermMinQ" id="leaseTermMinQ" type="text" class="ui-textbox" value="" validate="{digits:true}" ligerui="width: 89">
                   <span>—</span>
                   <input name="leaseTermMaxQ" id="leaseTermMaxQ" type="text" class="ui-textbox" value="" validate="{digits:true}" ligerui="width: 89">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">剩余租赁期数</div>
                <div class="field">
                   <input name="surplusLeaseTermMinQ" id="surplusLeaseTermMinQ" type="text" class="ui-textbox" value="" validate="{digits:true}" ligerui="width: 89">
                   <span>—</span>
                   <input name="surplusLeaseTermMaxQ" id="surplusLeaseTermMaxQ" type="text" class="ui-textbox" value="" validate="{digits:true}" ligerui="width: 89">
                </div>
            </div>
           <div class="fieldBox">
                <div class="label">逾期天数</div>
                <div class="field">
                   <input name="ovdDaysMin" id="ovdDaysMin" type="text" class="ui-textbox" value="" validate="{digits:true}" ligerui="width: 89">
                   <span>—</span>
                   <input name="ovdDaysMax" id="ovdDaysMax" type="text" class="ui-textbox" value="" validate="{digits:true}" ligerui="width: 89">
                </div>
            </div>
           <div class="fieldBox">
                <div class="label">资产包名称</div>
                <div class="field">
                   <input name="assPackNm" id="assPackNm" type="text" class="ui-textbox" value="" ligerui="width: 200">
                </div>
            </div>
             <div class="fieldBox">
                <div class="label">支付表号</div>
                <div class="field">
                   <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="" ligerui="width: 200">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
            	<!-- 隐藏融资筛选编号 -->
				<input name="fncInsIdQ" id="fncInsIdQ" type="hidden" class="ui-textbox" value="">
				<input name="flag" id="flag" type="hidden" class="ui-textbox" value="0">
				<input name="safeFlag" id="safeFlag" type="hidden" class="ui-textbox" value="${safeFlag}">
            	<input name="assPackName" id="assPackName" type="hidden" class="ui-textbox" value="">
                <span id="searchBtn" class="sq-button-round">查询</span>
                <span id="clearBtn" class="sq-button-round">清空</span>
                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
          </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>

<!-- 导出资产包-JL-20171117 -->
<form id="export_form" method="post"></form>

<script type="text/javascript">
	var grid = null;
	var safeFlag;
	$(function () {
		initbuOrgCd();
		initPackInfoList();
		//平安信托初始化 平安信托标示safeFlag=101
		var safeFlag='${safeFlag}';
		if(safeFlag!=null && safeFlag == '101'){//平安信托
			
			$("#assPackNm").attr("disabled", "disabled");
		}
	});
	
	function initPackInfoList(){
		$("#searchBar").ligerForm({validate: true});
		var _url = '<%=path%>/ass/asspackinfo/initPackInfoList.do';
		//平安信托标示safeFlag=101[REQ-3345扩展成外部机构标识]
		var safeFlag='${safeFlag}';
		if(safeFlag!=null && safeFlag == '101'){//平安信托[REQ-3345扩展成外部机构]
			grid = $("#ligergrid1").ligerGrid({//REQ-3345去掉条件[assPackNm=平安信托]
		   		url :'<%=path%>/ass/asspackinfo/initPackInfoList.do?', 
		   		method : 'get',
		       	columns: [
		       		{ display: '操作', width: 120,height:'100px', align:'center',
		            	render: function (rowdata, rowindex, value){
		            		var h='<a href="javascript:showDetailPi(';
		            		h+="'"+rowdata.id+"'";
		            		h+=",'"+rowdata.fncPrjId+"'";
		            		h+=",'"+rowdata.insUserFlag+"'";
		                    h+=')">查看</a>';
		                	return h;
		            	}
		            },
		            { display: '资产包名称', name: 'assPackNm', width: 200},
		            { display: '项目名称', name: 'fncPrjNm', width: 180},
		            { display: '融资基数', name: 'fncCrdnltNm', width: 100},
		            { display: '客户类型', name: 'cstTypCdNm', width: 120, render:renderCstTypCdNm},
		            { display: '是否办理抵押', name: 'isMgtNm', width: 80, render:renderIsMgtNm},
		            { display: '是否有保险', name: 'isInsureNm', width: 80, render:renderIsInsureNm},
		            { display: '替换状态', name: 'repStNm', width: 100}
		        ],
		        pageSize:10, 
		        root:'rows',
		        record:'total',
		        hideLoadButton : true,
		        width: '100%',
		        height:'100%',
		        heightDiff:-2,
		        checkbox:false,
		        rownumbers:true
		
		   	});
		}else{
		grid = $("#ligergrid1").ligerGrid({
	   		url : _url,
	   		method : 'get',
	       	columns: [
	       		{ display: '操作', minWidth: 280 ,height:'100px', align:'center',
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">查看</a>';
	                    h+=' | ';
	                    h+='<a href="javascript:showOldPayCode(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">旧支付表</a>';
	                    if(rowdata.fncPrjStcd == 14 || rowdata.fncPrjStcd == 0){
		                    h+=' | ';
		                    h+='<a href="javascript:modifyRow(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')">修改</a>';
	                    }
	                    if(rowdata.repSt == 0 && rowdata.fncPrjStcd != 13){
		                    h+=' | ';
		                    h+='<a href="javascript:replaceRow(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')">资产替换</a>';
	                    }
	                    h+=' | ';
	                    h+='<a href="javascript:copyRow(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">资产包复制</a>';
	                    //导出资产包-JL-20171117
	                    h+=' | ';
	                    h+='<a href="javascript:exportexcel(';
	            		h+="'"+rowdata.id+"'";
	                    h+=",'"+rowdata.fncCrdnlt+"'";
	                    h+=')">导出Excel</a>';
	                	return h;
	            	}
	            },
	            { display: '资产包名称', name: 'assPackNm', width: 200},
	            { display: '项目名称', name: 'fncPrjNm', width: 180},
	            { display: '融资基数', name: 'fncCrdnltNm', width: 100},
	            { display: '客户类型', name: 'cstTypCdNm', width: 120, render:renderCstTypCdNm},
	            { display: '是否办理抵押', name: 'isMgtNm', width: 80, render:renderIsMgtNm},
	            { display: '是否有保险', name: 'isInsureNm', width: 80, render:renderIsInsureNm},
	            { display: '替换状态', name: 'repStNm', width: 100}
	        ],
	        pageSize:10, 
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:false,
	        rownumbers:true
	
	   	});
		}
	    //grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	}
	
	$("#searchBtn").click(function(event) {
	    var form = new liger.get("searchBar");
	    if (!form.valid()) {
			top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return false; //验证不通过，不执行以下代码
		}
	    $("#flag").val("1");
	    var data = form.getData();
	    for (var name in data){
	       grid.setParm(name,data[name]);
	    };
	   grid.reload();
	});
	
	$("#clearBtn").click(function(event) {
	    $("#resetBtn").click();  //重置 input-text
	    var form = liger.get("searchBar");
	    form.setData({  //重置select等特殊表单
	        "fncCrdnlt": " ",
	        "cstTypCd": " ",
	        "buOrgCd": " ",       
	        "isMortgage": " ",
	        "isInsurance": " ",
	        "leaseTermMinQ": "",
	        "leaseTermMaxQ": "",
	        "surplusLeaseTermMinQ": "",
	        "surplusLeaseTermMaxQ": "",
	        "ovdDaysMin": "",
	        "ovdDaysMax": "",
	        "assPackNm": ""
	    });
	});
	
	//所属事业部
	function initbuOrgCd(){
		$("#buOrgCd").ligerComboBox({ 
			url: '<%=path%>/ass/asspackinfo/getbuOrgCd.do',
			ajaxType :'GET',
            slide: false,
            selectBoxHeight: 200,
            valueField: 'key', 
            textField: 'value',
            isMultiSelect: true
        });
	}
	
	//查看数据
	function showDetail(_id){
		var paySchNo=$('#paySchNo').val();
		var params = "?id="+_id+"&flag=0&paySchNo="+paySchNo;
		Add_navTab('ass_pack_info_view_'+_id,'查看资产包筛选信息','<%=path%>/ass/asspackinfo/viewAssPackInfoDetail.do'+params);
	}
	//查看数据(平安信托资产包查看)
	function showDetailPi(_id,fncPrjId,insUserFlag){
		var params = "?id="+_id+"&flag=0&pianflag=101&fncPrjId="+fncPrjId+"&insUserFlag="+insUserFlag;
		Add_navTab('ass_pack_info_view_'+_id,'查看资产包筛选信息','<%=path%>/ass/asspackinfo/viewAssPackInfoDetail.do'+params);
	}
	//修改
	function modifyRow(_id){
		var params = "?id="+_id+"&flag=1";
		Add_navTab('ass_pack_info_modify_'+_id,'修改资产包筛选信息','<%=path%>/ass/asspackinfo/viewAssPackInfoEdit.do'+params);
	}
	
	//资产替换
	function replaceRow(_id){
		var params = "?id="+_id;
		Add_navTab('ass_pack_info_replace_'+_id,'资产包替换','<%=path%>/ass/asspackinfo/replaceAssPackInfo.do'+params);
	}
	
	//资产包复制
	function copyRow(_id){
		addAssPackNm(_id);
	}
	
	//添加资产包名称
	function addAssPackNm(_id){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 430,
            height:120,
            title : '新增资产包名称',
            url:'<%=path%>/ass/asspackinfo/toAddPackInfo.do?flag=' + _id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) {
                        	Dialog.onOk();
                        }
                        
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}
	
	 //复制数据
	function add(assPackId){
		var _url = '<%=path%>/ass/asspackinfo/copyAssPackInfo.do?';
		var assPackNm = $("#assPackName").val();
		//发送异步请求校验
		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType: 'json',
			data: {"assPackId":assPackId, "assPackNm":assPackNm},
			url: _url,
			beforeSend: function(){
		          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					grid.reload();
					frameElement.dialog.close();
				 }else if(msg.success == 0 && !msg.data){//校验不成功,且没有data(id)报错
					top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					frameElement.dialog.close();
				 }
			}
		});
	 }
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	//格式化客户类型
	function renderCstTypCdNm(rowdata, index, value){
		var dateStr = "自然人,法人";
		if(null != value){
			dateStr = value;
		}
		return dateStr;
	}
	
	//格式化事业部
	function renderBuOrgCdNm(rowdata, index, value){
		var dateStr = "全部";
		if(null != value){
			dateStr = value;
		}
		return dateStr;
	}
	
	//格式化是否办理抵押
	function renderIsMgtNm(rowdata, index, value){
		var dateStr = "是,否";
		if(null != value){
			dateStr = value;
		}
		return dateStr;
	}
	
	//格式化是否有保险
	function renderIsInsureNm(rowdata, index, value){
		var dateStr = "是,否";
		if(null != value){
			dateStr = value;
		}
		return dateStr;
	}

	//刷新列表
	function reloadAssPackInfoList(){
		 grid.reload();
	}
	
	//导出资产包-JL-20171117
	function exportexcel(id,fncCrdnlt){
		var parms = "id="+id+"&fncCrdnlt="+fncCrdnlt+"&page=1&pagesize=10000";
		var url = '<%=path%>/rfbuss/fncprjbscinfo/exportExcel.do?'+parms;
		$('#export_form').attr('action', url);  
        $('#export_form').submit();
	}
	//查看导入的旧支付表号
	function showOldPayCode(id){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 500,
            height:500,
            title : '导入的旧支付表号',
            url:'<%=path%>/ass/asspackinfo/showOldPayCode.do?id='+id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no2', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}
</script>
</body>
</html>